package com.zz.ecommerce.declareManage.declareDetail;

import com.zz.ecommerce.common.GridRequest;
import com.zz.ecommerce.common.GridResult;
import com.zz.ecommerce.common.constants.TableConstants;
import com.zz.ecommerce.declareManage.exportB2CDeclare.declareManage.CbecElistDao;
import com.zz.ecommerce.declareManage.exportB2CDeclare.declareManage.CbecElistItemDao;
import com.zz.ecommerce.pojo.CbecElist;
import com.zz.ecommerce.pojo.CbecElistItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by admin on 2016/3/29.
 * <p>
 * 申报清单详情Controller
 */
@Controller
@RequestMapping("/declareDetail")
@Scope("prototype")
public class DeclareDetailController {

    @Autowired
    private CbecElistDao cbecElistDao;

    @Autowired
    private CbecElistItemDao cbecElistItemDao;

    /**
     * 申报清单详情页跳转
     *
     * @return
     */
    @RequestMapping(value = "declareDetail/{elistNo}", method = {RequestMethod.GET})
    public String declareDetail(@PathVariable("elistNo") String elistNo, ModelMap map) {
        map.addAttribute("elistNo", elistNo);
        return "declareManage/declareDetail/declare_detail";
    }

    /**
     * 申报清单详情页--表头
     *
     * @return
     */
    @RequestMapping(value = "declareDetailHead/{elistNo}", method = {RequestMethod.GET})
    public String declareDetailHead(@PathVariable("elistNo") String elistNo, ModelMap map) {
        map.addAttribute("elistNo", elistNo);
        return "declareManage/declareDetail/declare_detail_head";
    }

    /**
     * 申报清单详情页--表体
     *
     * @return
     */
    @RequestMapping(value = "declareDetailBody/{elistNo}", method = {RequestMethod.GET})
    public String declareDetailBody(@PathVariable("elistNo") String elistNo, ModelMap map) {
        map.addAttribute("elistNo", elistNo);
        return "declareManage/declareDetail/declare_detail_body";
    }

    /**
     * 清单表头详情
     *
     * @param cbecElist
     * @return
     */
    @RequestMapping("/getCbecElist")
    @ResponseBody
    public CbecElist getCbecElist(CbecElist cbecElist) {
        return cbecElistDao.query(TableConstants.CBEC_ELIST, cbecElist);
    }


    /**
     * 清单表体列表
     *
     * @param cbecElistItem
     * @param request
     * @return
     */
    @RequestMapping("/queryCbecElistItemList")
    @ResponseBody
    public GridResult queryCbecElistItemList(CbecElistItem cbecElistItem, GridRequest request) {
        return new GridResult(cbecElistItemDao.page(TableConstants.CBEC_ELIST_ITEM, cbecElistItem, request.getStart(), request.getEnd(), request.getSortOrder()), request, cbecElistItemDao.count(TableConstants.CBEC_ELIST_ITEM, cbecElistItem));
    }


    /**
     * 清单表体详情
     *
     * @param cbecElistItem
     * @return
     */
    @RequestMapping("/getCbecElistItem")
    @ResponseBody
    public CbecElistItem getCbecElistItem(CbecElistItem cbecElistItem) {
        return cbecElistItemDao.query(TableConstants.CBEC_ELIST_ITEM, cbecElistItem);
    }
}
